package share.storage;

import java.util.ArrayList;
import java.util.List;

import share.storage.io.File;
import share.storage.io.FileReader;
import share.storage.io.FileType;

public class RootFile implements File {

	String name=null;
	File parent=null;
	/**
	 * 
	 */
	private static final long serialVersionUID = 737997351444543032L;
	List<File> children = new ArrayList<File>();

	public long getSize() {
		return 0;
	}

	public boolean isDirectory() {
		return true;
	}

	public boolean isFile() {
		return false;
	}

	public File[] getChildren() {
		File[] fs = new File[children.size()];
		return children.toArray(fs);
	}

	public FileReader getReader() {
		return null;
	}

	public String getFilename() {
		if(name!=null)
			return name;
		return "/";
	}

	public File getParent() {
		if(parent!=null)
			return parent;
		return null;
	}

	public void addChild(File file) {
		children.add(file);
	}

	public void setParent(File parent) {
		this.parent=parent;
	}

	public void setFileName(String name) {
		this.name=name;
	}

	public File findChildByName(String name) {
		for (File file : children) {
			if (file.getFilename().equals(name))
				return file;
		}
		return null;
	}

	public boolean isHidden() {
		return false;
	}

	public String getDescribe() {
		return null;
	}

	public long lastModified() {
		long last = 0;
		for (int i = 0; i < children.size(); i++) {
			if (children.get(i).lastModified() > last)
				last = children.get(i).lastModified();
		}
		return last;
	}

	public void setDescribe(String describe) {
		// TODO Auto-generated method stub

	}

	public FileType getFileType() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setFileType(FileType type) {
		// TODO Auto-generated method stub
		
	}

}
